<template>
<div id="background">
    <el-container>
        <el-header id="editZhiYeHeadPosition">
                 <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                       <el-col :xs="2" :sm="2" :md="2" :offset="1" class="imgCol">
                        <img v-bind:src="backIcon" class="backSize" @click="back"/>
                    </el-col>
                    <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol"> 
                        <span class="titleSize">编辑职业</span>
                    </el-col>
                    <el-col :xs="3" :sm="6" :md="6" :offset="5" class="imgCol">
                        <span class="titleSize" @click="editZhiYe">保存</span>
                    </el-col>
                </el-row>
        </el-header>
        <el-main id="editZhiYeMainPosition">
            <el-row type="flex"  class="rowHeight" >
                <el-col class="imgCol">
                    <van-field
                        readonly
                        clickable
                        label="职业"
                        :value="occupation"
                        placeholder="选择职业"
                        @click="show = true"
                    />
                    <van-popup v-model="show" position="bottom">
                        <van-picker
                            show-toolbar
                            :columns="zhiYes"
                            :default-index="zhiYe"
                            @cancel="show = false"
                            @confirm="confirm"
                        />
                    </van-popup>
                </el-col>
            </el-row>
        </el-main>
    </el-container>
</div>    
</template>
<script>
import backIcon from '../../assets/img/mine/geRenZhongXin/back.png'
import { Toast } from 'vant';
export default {
    data(){
        return{
            show:false,
            occupation:'',
            backIcon:backIcon,
            normalHeight:document.documentElement.clientHeight,
            zhiYes:['电工', '技工', '汽修工', '焊工', '车工'],
            zhiYe: '',
        }
    },
    mounted(){
    //     var bg = document.getElementById("background");
    //    // normalHeight=document.documentElement.clientHeight;
    //     console.log("height:"+normalHeight);
    //     bg.style.height = normalHeight+"px";
    //     bg.style.backgroundColor = "#FFFFFF"
    //     bg.style.margin = "0px";
        var normalHeight=sessionStorage.getItem('normalHeight');
        var head=document.getElementById("editZhiYeHeadPosition");
        var headHeight=normalHeight/30 *4 ;
        console.log("headHeight:"+headHeight);
        head.style.height=headHeight+"px";

        
        var main=document.getElementById("editZhiYeMainPosition");
        var mainHeight=normalHeight/30 *26;
        console.log("mainHeight:"+mainHeight);
        main.style.height=mainHeight+"px";

        var occupation=this.$route.query.occupation;
        if(occupation==null){
            this.occupation='';
        }else{
                this.occupation=occupation;
                console.log(this.occupation);
                var index = this.zhiYes.findIndex(item=> item=== occupation);
                this.zhiYe=index;
                console.log(this.zhiYe);
        }

    },
    methods:{
        back(){
            console.log("back:");
            this.$router.go(-1);
        },
        selectType(){
            console.log("come in");
            this.show=true;
        },
        //点击确认时的回调
        confirm(val){
            console.log(val);
            this.occupation=val;
            this.show=false;
        },
        //保存职业
        editZhiYe(){
            var URL=this.IP.IP+'/user/userInfo';
            console.log(URL);
            console.log(this.occupation);
            this.$ajax({
                method:'post',
                url:URL,
                params:{
                    occupation:this.occupation
                },        
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    Toast(response.data.data);
                     setTimeout(()=>{
                        this.back();
                    },500)
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        }
 
    }
}
</script>
<style>
.rowHeight{
     height:10%;
    background-color: #ffffff;
    /* margin-top: 10px; */

}

.imgCol{
    display: flex;
    justify-content: center;
    align-items: center;
}
.el-main,.el-header,.el-footer,.el-aside {
    padding: 0px ;
}
#editZhiYeHeadPosition{
    background-color: #53cdf5;
}


.van-picker__cancel, .van-picker__confirm {
    color: #53cdf5 !important;
}
.van-cell {
    color: #707070;
    font-size: 1em;
    /* border-bottom: 1px solid #f5f4f9; */
}
.van-field__control {
    color: #707070;
}
 .van-picker-column__item {
    color: #707070;
}
.backSize{
    height: 26px;
}
.titleSize{
    /* font-size:1.125em; */
    color:#ffffff
}
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  /* .titleSize{
      font-size: 1em;
  } */
}
</style>
